package com.web.base.join;

import com.web.base.core.facade.BankFacade;
import com.web.base.core.message.BankResponse;
import com.web.core.join.BankJoin;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* 银行跨库连接信息处理器
* 
* @author zhengjin
* @since 1.0 2018年06月27日
*/
public class BankJoinHandler
{
    private BankJoinHandler()
    {
    }

    public static void bankJoin(List<? extends BankJoin> list, BankFacade bankFacade)
    {
        if (list == null || list.isEmpty() || bankFacade == null)
            return;

        Set<Integer> idList = list.stream().map(BankJoin::getBankId).collect(Collectors.toSet());
	    Map<Integer, BankResponse> map = bankFacade.getList(idList);
	    for (BankJoin join : list)
	    {
		    BankResponse bank = map.get(join.getBankId());
		    if (bank == null)
		    	continue;

		    join.setBankCode(bank.getCode());
		    join.setBankName(bank.getName());
		    join.setBankShortName(bank.getShortName());
	    }
    }

    public static void bankJoin(BankJoin join, BankFacade bankFacade)
    {
    	if (join == null || bankFacade == null)
    		return;

    	BankResponse bank = bankFacade.get(join.getBankId());
    	if (bank == null)
    		return;

    	join.setBankCode(bank.getCode());
    	join.setBankName(bank.getName());
    	join.setBankShortName(bank.getShortName());
    }
    
}
